package cn.baiweigang.uu.msg;

import cn.baiweigang.uu.BTContext;
import cn.baiweigang.uu.constants.BtcConfig;
import cn.baiweigang.uu.strategy.StrategyAction;
import cn.baiweigang.uu.utils.LogUtil;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class MsgListener {

    @Async("singleTaskExecutor")
    @EventListener
    public void priceChange(PriceChangeEvent priceChangeEvent) {
        LogUtil.logDebug("收到了价格更新消息");
//        LogUtil.logInfo(priceChangeEvent);
        //触发在运行的策略-价格变化处理
        StrategyAction strategyAction = BTContext.StrategyCache.get(BtcConfig.ACCOUNT_NAME);
        strategyAction.priceChange(priceChangeEvent.getPrice());
    }

    @Async("singleTaskExecutor")
    @EventListener
    public void orderChange(OrderChangeEvent orderChangeEvent) {
        LogUtil.logDebug("收到了订单更新消息");
//        LogUtil.logInfo(orderChangeEvent);
        //触发在运行的策略-订单变化处理
        StrategyAction strategyAction = BTContext.StrategyCache.get(BtcConfig.ACCOUNT_NAME);
        if (strategyAction != null) strategyAction.acceptTrade(orderChangeEvent.getTradeInfo());
    }

    @Async("singleTaskExecutor")
    @EventListener
    public void basisChange(BasisChangeEvent basisChangeEvent) {
        LogUtil.logDebug("收到了基差更新消息");
//        LogUtil.logInfo(orderChangeEvent);
    }

}
